package com.clg.common.velocity.toolbox;

import com.clg.common.constants.Constants;
import org.apache.commons.lang.StringUtils;
import org.apache.velocity.tools.view.ViewContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by usercai on 2016/9/29.
 */
public class ShowMessage {
    private HttpServletRequest request;

    public void init(Object obj) {
        if(obj instanceof ViewContext) {
            this.request = (((ViewContext)obj).getRequest());
        }
    }

    public String showErr(){
        String error = (String)request.getAttribute(Constants.BUSSINESS_ERR_KEY);
        if(StringUtils.isNotBlank(error)){
            return "<div class=\"alert alert-danger\">"+
                    "<strong>"+
                    "<i class=\"ace-icon fa fa-times\"></i>"+
                    "</strong>"+
                    error+
                    "<br></div>";
        }
        return null;
    }
}
